package com.bao.work.work01;

import org.junit.jupiter.api.Test;

import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author baoye
 * @date 2024-08-16/16:45
 */
public class Test01 {
    @Test
    public void test (){
        //1获取所有用户名字集合
        List<User> users = User.getUsers();
        users.stream().map(User::getName).collect(Collectors.toSet()).forEach(System.out::println);
        //2.获取年龄小于25的名字集合
        System.out.println("--------------------------------------");
        users.stream().filter(s -> s.getAge() < 25).map(User::getName).collect(Collectors.toList()).forEach(System.out::println);
        //3.分数倒
        System.out.println("--------------------------------------");
        users.stream().sorted(Comparator.comparing(User::getScore)).forEach(System.out::println);
        //4.睡觉
        System.out.println("--------------------------------------");
        users.stream().filter(s -> s.getHobby().contains("睡觉")).collect(Collectors.toList()).forEach(System.out::println);
        //5.
        System.out.println("--------------------------------------");
        users.stream().filter(s -> "德玛西亚".equals(s.getAddr())).sorted((s1, s2) -> s2.getScore().compareTo(s1.getScore())).map(User::getName).limit(2).forEach(System.out::println);
        //6.
        System.out.println("--------------------------------------");
        System.out.println((Integer) users.stream().mapToInt(User::getScore).sum());
    }
}
